/**
 * 消息级别
 *
 * @author timely-rain
 * @since 1.0.0, 2021/8/7
 */
export type RestMessageLevel = "debug" | "info" | "warning" | "error";

/**
 * REST消息体
 *
 * @author timely-rain
 * @since 1.0.0, 2021/8/7
 */
export class RestMessage {

  /**
   * 状态码
   *
   * @see RestMessageStatus
   */
  status: number;

  /**
   * 错误码
   */
  code?: string;

  /**
   * 消息级别
   *
   * @see RestMessageLevel 级别枚举
   */
  level?: string;

  /**
   * 消息内容
   */
  message: string;

  /**
   * 消息数据
   */
  data?: any;

  /**
   * 构造方法
   * @param status 状态码
   * @param message 消息内容
   */
  constructor(status = 200, message = "") {
    this.status = status;
    this.message = message;
  }
}

/**
 * REST状态码
 *
 * @author timely-rain
 * @since 1.0.0, 2021/8/7
 */
export class RestMessageStatus {

  /**
   * 成功状态
   */
  public static SUCCESS = 200;

  /**
   * 失败状态
   */
  public static FAILURE = 500;

  /**
   * 判断是否成功状态
   *
   * @param status 状态码
   * @return 是否成功
   */
  public static isSuccess(status: number): boolean {
    return status === RestMessageStatus.SUCCESS;
  }

  /**
   * 判断是否失败状态
   *
   * @param status 状态码
   * @return 是否失败
   */
  public static isFailure(status: number): boolean {
    return status === RestMessageStatus.FAILURE;
  }
}